/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       fontloader.cpp
 * Author:     karooolek
 * Created on: 2014-01-20
 *
 **********************************************************************************************************************/

#include "fontloader.h"
#include "ttfloader.h"
#include "glfloader.h"

namespace mGameEngine
{

namespace Graphics
{

Font *FontLoader::loadFontFromFile(const String &filename)
{
    FontLoader ld(filename);
    ld.load();
    return ld.getFont();
}

FontLoader::FontLoader() : FontFactory(), FileLoader()
{
}

FontLoader::FontLoader(const String &filename) : FontFactory(), FileLoader(filename)
{
}

FontLoader::~FontLoader()
{
}

void FontLoader::load()
{
    // begin loading
    _state = 0.0f;

    if(_extension == "ttf")
    {
        TTFLoader loader(_filename);
        loader.load();
        _font = loader.getFont();
        _state = loader.getLoadingState();
    }
    else if(_extension == "glf")
    {
        GLFLoader loader(_filename);
        loader.load();
        _font = loader.getFont();
        _state = loader.getLoadingState();
    }
    else
    {
        return;
    }
}

void FontLoader::unload()
{
    // no image to unload
    if(!_font)
    {
        _state = 0.0f;
        return;
    }

    delete _font;

    // end unloading
    _state = 0.0f;
}

}
}

